package com.weixin.pay.error;


import org.springframework.boot.web.server.ErrorPage;
import org.springframework.boot.web.server.ErrorPageRegistrar;
import org.springframework.boot.web.server.ErrorPageRegistry;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

@Component
public class HandleErrorPageConfiguration implements ErrorPageRegistrar {


    /**
     * 如果访问了错误的路径，或者后台报错，没有统一的提示页面，即影响美观，又对用户不太友好
     * 这样定义HandleErrorPageConfiguration，配置错误状态与对应的访问路径
     *
     * @param registry
     */
    @Override
    public void registerErrorPages(ErrorPageRegistry registry) {
        //按错误类型返回
        ErrorPage errorPage404 = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404");
        ErrorPage errorPage500 = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500");
        registry.addErrorPages(errorPage404, errorPage500);
    }
}
